from command import Command
from output import Output
from point import Point


class Input:
    # 输入玩家姓名
    @staticmethod
    def get_name() -> str:
        return input("Please enter your name: ")

    # 输入放置ship的信息
    @staticmethod
    def get_place_ship(ship, new_game=False) -> Command:
        alert_msg = "Enter the coordinates and direction for the "
        if new_game:
            alert_msg = "Please enter the coordinates and direction for the "
        alert_msg += ship.get_name() + ": "
        raw_command = input(alert_msg)
        command, err = Command.parse(raw_command)
        while err:
            Output.print_str("Ship not placed , the location you entered could not be recognised")
            raw_command = input(alert_msg)
            command, err = Command.parse(raw_command)
        return command

    # 输入攻击点的坐标
    @staticmethod
    def get_attack_point() -> Point:
        alert_msg = "Enter the coordinate you would like to hit: "
        raw_point = input(alert_msg)
        # parse函数有两个返回值，point表示
        point, err = Point.parse(raw_point)
        while err:
            Output.print_str('The coordinates you entered ("%s") could not be recognised , please try again'
                             % raw_point)
            raw_point = input(alert_msg)
            point, err = Point.parse(raw_point)
        return point
